package com.derbysoft.lowcostadapter.schedule.sync.impl;

import com.derbysoft.lowcostadapter.dswitch2.service.helper.Constant;
import com.derbysoft.lowcostadapter.schedule.parse.ParseRateCacheService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SyncRateCacheServiceImpl extends SyncFromFileServiceBase {

    public static final String SYNC_RATE_CACHE_TIMESTAMP = "SYNC_RATE_CACHE_TIMESTAMP";

    protected Logger logger = LoggerFactory.getLogger(getClass());

    private ParseRateCacheService parseRateCacheService;

    @Override
    protected boolean doSync() {
        try {
            boolean result = parseRateCacheService.importRoomTypes(getFileInputStream());
            return result && parseRateCacheService.importRateCaches(getFileInputStream());
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
        }
        return false;
    }

    @Override
    protected String getTimestampVariableName() {
        return SYNC_RATE_CACHE_TIMESTAMP;
    }

    @Override
    protected String getConfigVariableName() {
        return Constant.SYNC_RATE_CACHE_CONFIG;
    }

    public void setParseRateCacheService(ParseRateCacheService parseRateCacheService) {
        this.parseRateCacheService = parseRateCacheService;
    }
}
